<template>
  <view>
    <view class="disFlxCC" style="padding-top: 15vh">
      <image
        src="https://onelive.obs.cn-south-1.myhuaweicloud.com/uniapp/static/image220701%2817%29.png"
        style="width: 160rpx; height: 160rpx"
      />
      <view class="fz-16" style="padding-top: 34rpx; padding-bottom: 10vh">{{
        writeCode ? "订单支付成功" : "预约成功"
      }}</view>
      <view v-if="writeCode">
        <view>您的服务项目核销码为</view>
        <view class="fz-26 pt-6 tc" style="color: #bb9313">{{ writeCode }}</view>
      </view>
      <view v-else class="disFlx linh-30">
        <view class="pr-10 shrink0">
          <view>预约专家：</view>
          <view>所属单位：</view>
          <view>预约时间：</view>
          <view>咨询人：</view>
          <view>联系方式：</view>
        </view>
        <view>
          <view>{{ infoObj.userName }} {{ infoObj.postName || "" }}</view>
          <view class="ov-1" style="max-width:400rpx;">{{ infoObj.com }} {{ infoObj.deptname || "" }}</view>
          <view>{{ playInfo.timeText }}</view>
          <view>{{ playInfo.username }}</view>
          <view>{{ playInfo.userphone }}</view>
        </view>
      </view>
    </view>

    <view class="px-15 py-15 fexdBtn">
      <view class="tc pb-24" style="color: #ff2e2e">{{
        writeCode
          ? "温馨提示：可以截图保存核销码 到机构后出示核销码给工作人员，凭码进行检查。"
          : "温馨提示：请留意该时间段的医生视频邀请"
      }}</view>

      <u-button
        type="primary"
        text="回到首页"
        :customStyle="{
          fontSize: '32rpx',
          borderRadius: '20rpx',
          height: '88rpx',
        }"
        :throttleTime="500"
        @click="goPage('/pages/index/index')"
      ></u-button>
    </view>

    <OfficialAccount :show="accountShow" @close="accountShow = false" />
  </view>
</template>

<script>
import orderApi from "@/api/order";
import OfficialAccount from "@/components/officialAccount.vue";

export default {
  components: {
    OfficialAccount,
  },
  computed: {
    // 用户信息
    userInfo() {
      return this.$store.state.userInfo;
    },
  },
  data() {
    return {
      writeCode: "", // 核销码 - 证明是服务项目进入
      expertId: {},
      playInfo: {
        timeText: "",
        username: "",
        userphone: "",
      },
      infoObj: {},
      accountShow: false,
    };
  },
  onLoad(options) {
    if (options.writeCode) {
      this.writeCode = options.writeCode;
      uni.setNavigationBarTitle({title: '支付成功'});
    } else {
      this.expertId = options.expertId;
      this.playInfo.timeText = decodeURIComponent(options.timeText);
      this.playInfo.username = decodeURIComponent(options.username);
      this.playInfo.userphone = decodeURIComponent(options.userphone);
      this.getList();
    }
    if (!this.userInfo.mpOpenid) {
      // 未关注公众号
      this.accountShow = true;
    }
  },
  methods: {
    // 获取专家详情
    async getList() {
      const { data } = await orderApi.getExpertInfo({
        expertId: this.expertId,
      });
      if (this.scene && data.costMap) {
        // 扫码咨询,取优惠价格
        data.cost = data.costMap.newcost;
      }
      this.infoObj = data;
      console.log(JSON.parse(JSON.stringify(this.infoObj)));
    },
  },
};
</script>

<style lang="scss" scoped>
.fexdBtn {
  position: fixed;
  left: 0;
  width: 100%;
  bottom: 0;
  bottom: constant(safe-area-inset-bottom);
  bottom: env(safe-area-inset-bottom);
}
</style>